<template>
	<view class="container">
		<view class="blue_bg" />

		<view class="add" @click="toAddCoupons">
			<image src="@/static/images/ryx/asset/jia@2x.png"></image>
			<view class="font">
				新增优惠券
			</view>
		</view>

		<view class="coupons_tab">
			<view class="ing_over">
				<uni-segmented-control :current="current" :values="items" :style-type="styleType"
					:active-color="activeColor" @clickItem="oncurrent" />
			</view>

			<view class="content">
				<view v-if="current === 0">
					<view v-for="(item,index) in coupons_list" :key="index" class="coupons" v-if="item.type==1">
						<view class="coupons_left">
							<view class="coupons_man">
								满{{item.full}}元可用
							</view>
							<view class="coupons_jian">
								￥<text>{{item.reduce}}</text>
							</view>
						</view>
						<view class="coupons_right">
							<view class="coupons_name">
								优惠券名称:{{item.name}}
							</view>
							<view class="coupons_date">
								有效期:{{item.endTime}}
							</view>
							<view class="coupons_limit">
								每人限领{{item.limited}}张
							</view>
						</view>

					</view>
				</view>

				<view v-if="current === 1">
					<view v-for="(item,index) in coupons_list" :key="index" class="coupons coupons_over">
						v-if="item.type==2">
						<view class=" coupons_left">
							<view class="coupons_man">
								满{{item.full}}元可用
							</view>
							<view class="coupons_jian">
								￥<text>{{item.reduce}}</text>
							</view>
						</view>
						<view class="coupons_right">
							<view class="coupons_name">
								优惠券名称:{{item.name}}
							</view>
							<view class="coupons_date">
								有效期:{{item.endTime}}
							</view>
							<view class="coupons_limit">
								每人限领{{item.limited}}张
							</view>
						</view>
						<image src="@/static/images/ryx/asset/over@2x.png" class="over_img"></image>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: ['进行中', '已结束'],
				current: 0,
				activeColor: '#007aff',
				styleType: 'button',
				coupons_list: []

			}
		},
		onLoad() {
			this.list();

		},
		methods: {
			list() {
				let that = this;
				this.$http({
					url: '/api/shanghuliebiao2/coupon/list',
					method: 'GET',
					success(res) {
						if (res.statusCode == 200) {
							console.log(res)
							that.coupons_list = res.data.rows

							console.log(that.coupons_list)
						} else {
							alert("错误")
						}

					}
				})
			},



			oncurrent(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
				console.log(e)
			},
			toAddCoupons() {
				uni.navigateTo({
					url: '/pages/ryx/Coupons-Manage/AddCoupons'
				})
			}
		}
	}
</script>

<style scoped>
	@import '@/static/images/ryx/all.css';

	.add {
		height: 8vh;
		width: 85vw;
		margin-top: 5vh;
		margin-bottom: 5vh;
		border-radius: 40rpx;
		display: flex;
		flex-flow: row;
		align-items: center;
		justify-content: center;
		background-color: #fff;
	}

	.add image {
		height: 5vw;
		width: 5vw;
		margin: 20rpx;
	}

	.add .font {
		font-size: 5vw;
		margin: 20rpx;
		color: #2679f5;
	}

	.ing_over {
		width: 50vw;
		/* border-radius: 50rpx; */
		overflow: hidden;
	}

	/* .segmented-control__item--button.data-v-064e9cd1 {
		border-style: none !important;
	} */

	.coupons_tab {
		width: 80vw;
		padding: 5vw;
		border-radius: 20rpx;
		display: flex;
		flex-flow: column;
		align-items: center;
		justify-content: center;
		background-color: #fff;
	}

	.coupons {
		height: 20vh;
		width: 100%;
		margin: 20rpx;
		border-radius: 20rpx;
		overflow: hidden;
		display: flex;
		flex-flow: row nowrap;
		position: relative;
	}

	.coupons_left {
		width: 30%;
		height: 100%;
		padding: 40rpx 5rpx 40rpx 5rpx;
		color: white;
		background-color: #ff7127;
	}

	.coupons_man {
		font-size: 30rpx;
		text-align: center;
	}

	.coupons_jian {
		text-align: center;
	}

	.coupons_jian text {
		font-size: 80rpx;
		font-weight: bold;
	}

	.coupons_right {
		width: 70%;
		height: 100%;
		padding: 40rpx 0rpx 40rpx 20rpx;
		background-color: #fff3eb;
	}

	.coupons_name {
		font-size: 30rpx;
	}

	.coupons_date {
		font-size: 25rpx;
	}

	.coupons_limit {
		font-size: 30rpx;
		margin-top: 50rpx;
	}

	.coupons_over {
		opacity: 0.5;
	}

	.over_img {
		position: absolute;
		right: 3vh;
		top: 12vh;
		width: 165rpx;
		height: 88rpx;
	}
</style>